function getID(id){
	return document.getElementById(id);
}

function getID_InnerHtml(id, value){
	getID(id).innerHTML = value;
}

function showThisID(id){
	getID(id).style.display='';
}

function hideThisID(id){
	getID(id).style.display='none';
}

function toggleThisID(id){	
	if( getID(id).style.display == 'none' ){
			showThisID(id);		
	}
	else{
		hideThisID(id);
	}
}

function disabledThisID(id){
	getID(id).disabled=true;
}

function enabledThisID(id){
	getID(id).disabled=false;
}

function assignValueForThisID(id, value){
	getID(id).value = value;
}

//String related

function trimAll(sString) 
{
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function isNotEmpty(str){
	if( str!=null && trimAll(str)!='' ){
		return true;
	}
	return false;
}

function isEmpty(str){
	if( str==null || trimAll(str)=='' ){
		return true;
	}
	return false;
}

function checkStrWithObj(obj, str){
	if( isNotEmpty(obj) && obj==str ) {
		return true;
	}
	return false;
}

function checkAndReturnValue(str){
	if( str!=null && trimAll(str)!='' ){
		return str;
	}
	return '';
}

// related to Radio option

function radioDefaultSelected(ID, defaultValue){
	var object = getID(ID);
	object.checked = (object.value == defaultValue);
}

function getRadioCheckedValue(radioObj) {
	
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


// related to Select Options

function removeAllSubObjects(id){
	var ObjectID = getID(id);
	while(ObjectID.length>0){
		ObjectID.removeChild(ObjectID.options[0]);				
	}
}

function removeAllSubObjectsExceptNone(id){
	var ObjectID = getID(id);
	while(ObjectID.length>1){
		ObjectID.removeChild(ObjectID.options[1]);				
	}
}

function addOptionChildToSelect(id, name, value){
	var ObjectID = getID(id);
	ObjectID.options[ObjectID.length] = new Option(name, value);	
}

function setSelectedOptionForGivenIndex(id, index){
	//form.callDetails_countryFrom[0].selected = "1";
	var obj = getID(id);
	obj[index].selected = "1";
}

// related to Table Manipulations

function removeRowsForGivenTable(tableName, initalRowCount){

	var sampleTable = getID(tableName);
	var rowCount = sampleTable.rows.length;
	while(rowCount>initalRowCount){	
		sampleTable.deleteRow(rowCount-1);
		rowCount = sampleTable.rows.length;
	}
}


// Array Related Functions

function isValueContainedInArray(arrObj, value){
	
	for(var i=0; i<arrObj.length; i++){
		if(arrObj[i]==value){
			return true;
		}
	}
	return false;
}

function sortAnArray(arrObj){
	arrObj.sort();
}

function removeObjectInArray(arrObj, index){
	arrObj.splice(index, 1);	
}

function distinctList(arrObj){
		
	var distinctArr = new Array;

	for(c in arrObj) {
		distinctArr[ arrObj[c] ] = c;
	}

	var i=-1;
	arrObj = new Array;
	for(c in distinctArr) {
		arrObj[++i] = c;
	}
	return arrObj;
}

/// validations

var tenDigitNmer=/^[0-9]{10}$/

function checktenDigit(num){	
	return tenDigitNmer.test(trimAll(num));
}

function isNumber(value){
	return !(isNaN(value));
}

function isNumberEntered(value){
	if( trimAll(value)=='' || !isNumber(value)){
		return false;
	}
	return true;
}

function isNotaNumber(value){
	if( trimAll(value)=='' || !isNumber(value)){
		return false;
	}
}

function showAlert(msg, colspanNumber){
	var fieldAlert = getID('fieldAlertTd');
	fieldAlert.innerHTML = "<ul><li>"+msg+"</li></ul>";
	showThisID('fieldAlert');	
}


/// on keyPress Validations

function checkKeyType(e) //Function/ AlphaNumeric/ Special Characters
{
	var code = 0;
	
	if(!e)	e = document.event;
	
	if(e) 
	{
		if(e.charCode == undefined)	
		{
			if(e.which == undefined || e.which != 0)
			{
				code = e.keyCode;		
			}
			else if(e.which == 0);
		}
		else if(e.charCode != 0)
		{
			code = e.which;
		}
		else if(e.charCode == 0) ;
	}

	return code;
}
	
function allow_only_digits(e){
	var code = checkKeyType(e);
	if(code != 0)
	{
		if ((code<48 || code >57))
		{
			//alert("Please enter only digits");
			
			e.cancelBubble = true;
			e.returnValue = false;

			if(e.which)
			{
				e.stopPropagation();
				e.preventDefault();
			}
		} 
	}
}